#include "Listener.h"

bool Listener::SearchEventMonitor(EventType event)
{
	if (EventMonitor.size() == 0)
	{
		return false;
	}

	std::list<EventType>::iterator Itor = EventMonitor.begin();

	while (Itor != EventMonitor.end())
	{
		if (!strcmp(event.getName(),Itor->getName()))
		{
			return true;
		}		
		Itor++;
	}
	return false;
}
bool Listener::AddEventMonitor(EventType event)
{
	//Check if the event is already being monitored by this Listener
	//If its not being watched, add it to the watch list
	if (SearchEventMonitor(event) == false)
	{
		EventMonitor.push_front(event);
	}
	return true;
}
bool Listener::DeleteEventMonitor(EventType event)
{
	if (EventMonitor.size() == 0)
	{
		return false;
	}

	std::list<EventType>::iterator Itor = EventMonitor.begin();

	while (Itor != EventMonitor.end())
	{
		if (!strcmp(event.getName(),Itor->getName()))
		{
			EventMonitor.erase(Itor);
			return true;
		}		
		Itor++;
	}

	return false;
}

bool Listener::ValidateEvent(EventType event)
{
	return false;
}
bool Listener::ValidateEvent(char eventName[])
{
	return false;
}
char * Listener::GetName()
{
	return name;
}
bool Listener::HandleEvent(EventType event)
{
	if (!strcmp(event.getName(),"EVENT_START_GAME1"))
	{
		printf("YOU JUST HANDLED EVENT_START_GAME1!!!!\n");
		return true;
	}
	if (!strcmp(event.getName(),"EVENT_START_GAME2"))
	{
		printf("YOU JUST HANDLED EVENT_START_GAME2!!!!\n");
		return true;
	}
	if (!strcmp(event.getName(),"EVENT_START_GAME3"))
	{
		printf("YOU JUST HANDLED EVENT_START_GAME3!!!!\n");
		return true;
	}
	if (!strcmp(event.getName(),"EVENT_START_GAME4"))
	{
		printf("YOU JUST HANDLED EVENT_START_GAME4!!!!\n");
		return true;
	}
	if (!strcmp(event.getName(),"EVENT_START_GAME5"))
	{
		printf("YOU JUST HANDLED EVENT_START_GAME5!!!!\n");
		return true;
	}
	return false;
}